<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <meta name="keywords"
        content="LED,显示屏,高清小间距LED显示屏,高清,小间距,户外全彩LED显示屏,室内全彩LED显示屏,LED照明,LED显示解决方案,大屏幕,LED显示屏生产厂家,LED显示屏报价，江西LED显示屏报价">
    <meta name="description" content="江西鑫磊光电科技有限公司是一家专业从事LED产品应用研发、设计、生产、销售和服务于一体的产品服务商。">
    <link rel="stylesheet" href="./zhanshi.css">
    <link rel="shortcut icon" href="./images/ifavion.ico">
    <script src="./js/jquery-3.6.0.min.js"></script>
</head>

<body>
    <div class="zhanshi">
        <!-- 顶部,导航栏开始 -->
        <?php include "./header.php" ?>
        <!-- 顶部,导航栏结束 -->
        <!-- 主体部分开始 -->
        <div class="main">
            <div>
                <!--aboutus banner开始 -->
                <div class="aboutus_banner">
                    <div>
                        <h4>NEWS</h4><br><span>咨讯中心</span>
                    </div>

                </div>
                <!-- banner结束 -->
                <!-- aboutus  主体部分开始 -->
                <div class="aboutus_main clearfix">
                    <div class="aboutus_left">
                        <div class="left_top clearfix">
                            <p>N</p>
                            <h3><span>ews</span><br>咨讯中心</h3>
                        </div>
                        <ul></ul>

                    </div>
                    <div class="aboutus_right">
                        <div class="right_top clearfix">
                            <h3>咨讯中心</h3>
                            <p>您的位置：首页 > 咨讯中心</p>
                        </div>
                        <div class="news_detail">
                            <div class="content_detail"></div>
                            <div class="index_news">
                                <li class="pre_news"></li>
                                <li class="next_news"></li>
                            </div>
                        </div>
                    </div>

                </div>
                <!-- aboutus  主体部分结束 -->
            </div>
        </div>
        <!-- 主体部分结束 -->
        <!-- 底部开始 -->
        <?php include "./bottom.php" ?>
        <!-- 底部结束 -->
    </div>
    <script>
        // 得到地址栏的地址
        function getQueryVariable(variable) {
            var query = window.location.search.substring(1);
            var vars = query.split("&");
            for (var i = 0; i < vars.length; i++) {
                var pair = vars[i].split("=");
                if (pair[0] == variable) {
                    return pair[1];
                }
            }
            return (false);
        }
        var id = getQueryVariable("id");

        // 时间戳转换为格式化时间
        function timestampToTime(timestamp) {
            //时间戳为10位需*1000，时间戳为13位的话不需乘1000
            var date = new Date(timestamp * 1000);
            Y = date.getFullYear() + '-';
            M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
            D = date.getDate() + ' ';
            h = date.getHours() + ':';
            m = date.getMinutes() + ':';
            s = date.getSeconds();
            return Y + M + D + h + m + s;
        }
        // var id=<?php echo $_GET["id"];?>;
        var sortid;
        $(function() {
            $.ajax({
                url: "./news_list.php",
                data: {
                    id: id
                },
                dataType: "json",
                success: function(res) {
                    if (res.code == 0) {
                        var listHtml = '';
                        res.list.forEach(el => {
                            var css = sortid == el.id ? "class='active'" : '';
                            listHtml +=
                                `<li><a href="news.php?sortid=${el.id}" ${css} id="list">${el.sortname}</a></li>`;
                        });
                        $(".aboutus_left>ul").html(listHtml);
                        var detail = '';
                        var time = timestampToTime(res.detail.time);
                        detail += `<h2>${res.detail.news_name}</h2>
                                        <div>
                                            <span>浏览次数：${res.detail.views}</span>
                                            <span>发布日期：${time}</span>
                                        </div>${res.detail.content}`;

                        $("title").text(res.detail.news_name);
                        $(".news_detail>.content_detail").html(detail);
                        $(".right_top>h3,.right_top>p>span").html(res.name);

                        var pre = '';
                        if (!res.pre) {
                            pre += `上一篇:没有了`;
                        } else {
                            var pre_id = id - 1;
                            pre = `上一篇:<a href="?id=${pre_id}">${res.pre["news_name"]}</a>`;
                        }
                        $(".news_detail>.index_news>.pre_news").html(pre);

                        var next = '';
                        if (!res.next) {
                            next += `下一篇:没有了`;
                        } else {
                            var next_id = parseInt(id) + 1;
                            next = `下一篇:<a href="?id=${next_id}">${res.next["news_name"]}</a>`;
                        }
                        $(".news_detail>.index_news>.next_news").html(next);

                    }
                }
            });
        })
    </script>
</body>

</html>